<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2019-04-08
 * Time: 14:50
 */

namespace app\wechatxcx\controller;

use app\common\model\UserLoginstatus;
use app\common\model\User;

class Base extends AllBase
{


    public $uid;
    public $userModel;

    public function __construct()
    {
        parent::__construct();
        self::checkToken();


    }

    public function checkToken()
    {
        //获取token
        $session_token = input("session_token");

        //未传递token则返回重新登录
        if (empty($session_token)) {
            $this->ajax(203, '请重新登录');
        }

        //验证token是否失效
        $this->uid = UserLoginstatus::getValue(array('session_token' => $session_token,'expire_time'=>array('>=',time())),'uid');

        //失效返回信息
        if (!$this->uid) {
            $this->ajax(203, 'token失效');
        }

        //获取用户信息
        $this->user = User::getOne(array('id' => $this->uid));
    }


}